<template>
  <div class="edit">
    <van-nav-bar :title="title">
      <template #left>
        <i @click="goBack" class="icon iconfont iconbtn_nav_back leftArro"></i>
      </template>
      <template #right>
        <span v-if="isShow" @click="save">保存</span>
      </template>
    </van-nav-bar>
    <div class="box">
      <van-field v-model="value" class="input" @input="isShow = true">
      </van-field>
    </div>
  </div>
</template>
<script>
import { apiEditUserInfo } from '@/api/login'
export default {
  created () {
    this.proto = this.$route.query.prototype
    console.log(this.proto)

    if (this.proto === 'nickname') {
      this.title = '修改昵称'
      //   this.value = this.$store.state.userInfo.nickname
    } else {
      this.title = '修改个人简介'
    }
    this.value = this.$store.state.userInfo[this.proto]
  },
  data () {
    return {
      title: '',
      proto: '',
      isShow: false,
      value: ''
    }
  },
  methods: {
    goBack () {
      this.$router.go(-1)
    },
    async save () {
      this.$toast.loading({
        duration: 0
      })
      //   if(proto==='nickname'){

      //       await apiEditUserInfo({ nickname: this.value })
      //   }else if(proto==='intro'){
      //       await apiEditUserInfo({ intro: this.value })
      //   }
      await apiEditUserInfo({ [this.proto]: this.value })
      this.$store.dispatch('setUserInfo')
      this.$router.push('/info')
      this.$toast.success('跟新成功')
    }
  }
}
</script>
<style lang="less">
.edit {
  .van-field__left-icon {
    margin-right: 15px;
  }
  .van-nav-bar__left {
    padding: 0;
  }
  .leftArro {
    font-size: 44px;
  }
  .box {
    margin: 15px;
    .input {
      background-color: #eee;
    }
  }
}
</style>
